import { any } from "../../core/logic";
import {ComponentType } from "../Component";
import { Light } from "./Light";
import {color} from "../../core/color";
/**
 * 区域光
 * @class
 * @extends w.light.Light
 * @memberof w.light
 */
class AreaLight extends Light{
    /**
     * @constructor
     * @param {*} opts 
     * @param {Number} opts.width 【可选,缺省:1】区域光照射区域的宽度。
     * @param {Number} opts.height 【可选,缺省:1】区域光照射区域的高度。
     * @example
     * let light=new w.light.AreaLight({width:10,height:10,color:"#ff0000",intensity:5});
     */
    constructor(opts={}){
        opts.type=any(opts.type,ComponentType.AreaLight);
        super(opts);
        this.lightbuffer=[];
        this.lightType=4;
        this._width = any(opts.width, 1);
        this._height = any(opts.height, 1);
        this.setState(true)
        this.autoUpdate=true;
        this.update();
    }
    /**
     * @property {Number} 区域光的区域宽度。
     */
    set width(v){
        this._width=v;
        this.setState(false,"lightBuffer");
        this.update();
        return this;
    }
    get width(){
        return this._width;
    }
     /**
     * @property {Number} 区域光的区域高度。
     */
    set height(v){
        this._height=v;
        this.setState(false,"lightBuffer");
        this.update();
        return this;
    }
    get height(){
        return this._height;
    }
    getLightBuffer(){
        if(!this.getState("lightBuffer")){
            let _color=color.format(this.color,false);
            this.lightbuffer= [..._color,//0-2
                this.lightType,//3 类型
                ...this.trans.position,//4-6 位置或方向
                this.intensity,//7 强度
                0,0,0,//8-10 距离
                0, //11 innerRad
                this.width,//12 innerRad|width
                this.height,//13 outerRad|height
                0,0,0//空白
            ];
            this.setState(true,"lightBuffer");
        }
        return this.lightbuffer;
    }
}
export {AreaLight}